Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve get_asset_relative_path(...) #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

strarsis
Copy link

This PR improves the get_asset_relative_path(...) by using WordPress constants, variables and functions to make it compatible with different types of WordPress configurations and setups (notably WordPress Bedrock).

Copy link
Owner

@kasparsd kasparsd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strarsis Please see my comments on this one.

Secondly, what is the value of $this->handler->base_url for those scripts that were failing in your case? Can you please mention some examples?

@@ -230,21 +230,17 @@ protected function get_asset_relative_path( $handle ) {
return false;
}

// Remove protocol reference from the local base URL
$base_url = preg_replace( '/^(https?:)/i', '', $this->handler->base_url );
$arr = explode(plugins_url(), $item_url);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strarsis What about plugins and WP core files? plugins_url() works only with assets in plugins.

return false;
}

// Get the trailing part of the local URL
$maybe_relative = array_pop( $src_parts );
$path_abs = WP_PLUGIN_DIR . $url_rel;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, WP_PLUGIN_DIR is plugin only.

@strarsis
Copy link
Author

strarsis commented Mar 24, 2017

$this->handler->base_url is always http://<hostname>/wp,
plugin files are in http://<hostname>/app/plugins,
theme files are in http://<hostname>/app/themes.

@kasparsd: I modified the function to handle also theme specific URLs.
The function currently doesn't return a relative path but an absolute path, but after adjusting the other code to expect an absolute function it actually works now in my WordPress Bedrock setup.
Edit: Now I understand why a relative path is expected, the URLs in the CSS files are adjusted, too.

@strarsis
Copy link
Author

strarsis commented Mar 24, 2017

$this->handler->base_url is http://<hostname>/wp - but the themes are http://<hostname>/app/themes - the URLs in these CSS files don't work because they assume a '/wp' prefix.

@kasparsd:
resolve_urls(...) and resolve_imports(...) have to differentiate between plugins and theme URLs.
For each URL, also the type has to be stored so minit later knows what kind of resource it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants